From 84fdd943aee9fdf199f6668145246d3021527c29 Mon Sep 17 00:00:00 2001
From: Rosen Penev <rosenp@gmail.com>
Date: Sun, 11 Oct 2020 22:10:45 -0700
Subject: [PATCH] remove usleep

usleep is removed in POSIX 2008.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 term.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

--- a/term.c
+++ b/term.c
@@ -33,6 +33,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
+#include <time.h>
 #include <unistd.h>
 #include <termios.h>
 #ifdef USE_FLOCK
@@ -1588,6 +1589,8 @@ term_drain(int fd)
 
     rval = 0;
 
+    struct timespec s;
+
     do { /* dummy */
 
         r = term_find(fd);
@@ -1614,7 +1617,10 @@ term_drain(int fd)
            the port is immediately reconfigured, even after a
            drain. (I guess, drain does not wait for everything to
            actually be transitted on the wire). */
-        if ( DRAIN_DELAY ) usleep(DRAIN_DELAY);
+        if ( DRAIN_DELAY ) {
+            struct timespec d = {0, DRAIN_DELAY * 1000};
+            nanosleep(&d, &s);
+        }
 
     } while (0);
 
@@ -1627,6 +1633,7 @@ int
 term_fake_flush(int fd)
 {
     struct termios tio;
+    struct timespec s;
     int rval, i, r;
 
     rval = 0;
@@ -1666,7 +1673,10 @@ term_fake_flush(int fd)
             break;
         }
         /* see comment in term_drain */
-        if ( DRAIN_DELAY ) usleep(DRAIN_DELAY);
+        if ( DRAIN_DELAY ) {
+            struct timespec d = {0, DRAIN_DELAY * 1000};
+            nanosleep(&d, &s);
+        }
         /* Reset flow-control to original setting. */
         r = tcsetattr(fd, TCSANOW, &term.currtermios[i]);
         if ( r < 0 ) {
